package priv.pront.code.mati.province;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-11-15 16:10
 */
public class MC0114_甄别情报 {

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(bf.readLine());
        while (n-- > 0) {
            Map<Character, Character> amap = new HashMap<>();
            Map<Character, Character> bmap = new HashMap<>();
            String[] s = bf.readLine().split(" ");
            if(s[0].length() != s[1].length()){
                System.out.println("No");
                continue;
            }
            boolean flag = true;
            for (int i = 0; i < s[0].length(); i++) {
                if (!amap.containsKey(s[0].charAt(i))) {
                    amap.put(s[0].charAt(i), s[1].charAt(i));
                }
                if (!bmap.containsKey(s[1].charAt(i))) {
                    bmap.put(s[1].charAt(i), s[0].charAt(i));
                }

                char acur = amap.get(s[0].charAt(i));
                char bcur = bmap.get(s[1].charAt(i));
                if (acur != s[1].charAt(i) || bcur != s[0].charAt(i)) {
                    flag = false;
                    System.out.println("NO");
                    break;

                }
            }
            if(flag){
                System.out.println("YES");
            }
        }
    }
}
